package com.cuit.jifver.weibo.data;

import android.content.Context;
import android.util.Log;


import com.cuit.jifver.weibo.model.HomeTimeLineRequest;
import com.cuit.jifver.weibo.model.TextMessage;
import com.cuit.jifver.weibo.model.WeiBoList;
import com.cuit.jifver.weibo.net.SyncHttp;
import com.cuit.jifver.weibo.utils.Constants;
import com.cuit.jifver.weibo.utils.LogUtil;
import com.cuit.jifver.weibo.utils.TextUtil;
import com.google.gson.Gson;


public class QqWeibo extends Weibo
{

	@Override
	public String publishTextMessage(Context context, TextMessage message)
	{
		String str = null;
		
		
		/*WeiboParameters params = new WeiboParameters();
		params.add("format", "json");
	
		params.add("content", message.getContent());
		
		params.add("clientip", "127.0.0.1");
		
		try
		{
		WeiboParameters parameters = OAuth.getHttParameters("post", Constants.qq.URL_PUBLISH_TEXT_MESSAGE, params, Weibo.getInstance().getAccessToken(), Weibo.getInstance().getAccessSecret());
		SyncHttp http = new SyncHttp();
		str = http.httpPost(Constants.qq.URL_PUBLISH_TEXT_MESSAGE, SyncHttp.convertHttpParamterToString(parameters));
		} catch (Throwable e)
		{
			e.printStackTrace();
		}*/
		getHomeTimeLine(context, null);
		return str;
	}

	@Override
	public WeiBoList getHomeTimeLine(Context context, HomeTimeLineRequest request)
	{
		String str = null;
		WeiBoList weiBoList = null;
		WeiboParameters params = new WeiboParameters();
		params.add("format", "json");
		params.add("pageflag", "0");
		params.add("pagetime", "0");
		params.add("reqnum", "10");
		params.add("type", "0");
		params.add("contenttype", "0");
		params.add("accesslevel", "0");
		
		try
		{
			WeiboParameters parameters = OAuth.getHttParameters("get", Constants.qq.URL_HOME_TIME_LINE, params, Weibo.getInstance().getAccessToken(), Weibo.getInstance().getAccessSecret());
			SyncHttp http = new SyncHttp();
			str = http.httpGet(Constants.qq.URL_HOME_TIME_LINE, parameters);
			//TextUtil.witeFile("qqhome.xml", str);
			Gson gson = new Gson();
			weiBoList = gson.fromJson(str, WeiBoList.class);
			LogUtil.d(this, "gson="+weiBoList.getData().getInfo().size());
		} catch (Throwable e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		LogUtil.i(this, "hometimeline="+str);
		//TextUtil.witeFile("test.json", str);
		return weiBoList;
	}

}
